import $axios, { Result } from '@/plugins/axios'
import { AxiosResponse } from 'axios'
import { PageParam } from '@/type'
import { IFileObj } from '@/type/file'
import { TApproveRecords } from '@/plugins/approve'
import { EApproveStatus } from '@/components/statusShow/util'

export interface ICoordinationApplicationDetail {
  matterTitle?: string
  applyTopic?: string
  applyUnitId?: number
  applyUserId?: number
  applyTime?: string
  coordinationDeptId?: number[] | string
  applyReason?: string
  dealDeadline?: string
  applyUserName?: string
  applyUnitName?: string
  uuid?: string
  matterId?: number
  approveUserName?: string
  approveResult?: EApproveStatus
  coordinationDeptName?: string
  audioDataVos?: IFileObj[]
  matterSubProcessVos?: TApproveRecords
  applyStatus?: EApproveStatus
  approveUserId?: number
}

/**
 * AuditApplyProcessVo
 */
export interface IApproveRequest {
  /**
   * 申请类型1-延期 2-协调
   */
  applyType?: number
  /**
   * 子流程处理Id(t_matter_sub_process_id)
   */
  id?: number
  /**
   * No comments found.
   */
  processOpinion?: string
  /**
   * 处理结果：1通过/2不通过
   */
  processResult?: number
  /**
   * No comments found.
   */
  processUserId?: number
  [property: string]: any
}
/**
 * 获取协调申请列表
 * @param param 分页查询参数
 * @returns
 */
export async function getCoordinationApplicationList(
  param: PageParam,
): Promise<AxiosResponse<Result>> {
  return await $axios.post(
    '/supervision-api/coordinationApply/getCoordinationApply',
    {
      ...param,
    },
  )
}

/**
 * 获取协调申请审核列表
 * @param param 分页查询参数
 * @returns
 */
export async function getCoordinationApplicationApproveList(
  param: PageParam,
): Promise<AxiosResponse<Result>> {
  return await $axios.post(
    '/supervision-api/coordinationApply/getPendingAuditCoordinationApply',
    {
      ...param,
    },
  )
}

/**
 * 根据id查询详情
 * @param id
 */
export async function getCoordinationApplicationDetailById(
  id: number,
): Promise<AxiosResponse<Result>> {
  return await $axios.get(
    '/supervision-api/coordinationApply/getCoordinationApplyById',
    {
      params: {
        id,
      },
    },
  )
}

/**
 * 保存或更新
 * @param
 * @returns
 */
export async function saveOrUpdateCoordinationApplication(
  param: ICoordinationApplicationDetail,
): Promise<AxiosResponse<Result>> {
  return await $axios.post(
    '/supervision-api/coordinationApply/saveOrUpdateApplyInfo',
    {
      ...param,
    },
  )
}

/**
 * 提交
 * @param
 * @returns
 */
export async function submitCoordinationApplication(
  param: ICoordinationApplicationDetail,
): Promise<AxiosResponse<Result>> {
  return await $axios.post(
    '/supervision-api/coordinationApply/submitApplyInfo',
    {
      ...param,
    },
  )
}

/**
 * 审核
 * @param
 * @returns
 */
export async function approveCoordinationApplication(
  param: IApproveRequest,
): Promise<AxiosResponse<Result>> {
  return await $axios.post(
    '/supervision-api/coordinationApply/auditApplyInfo',
    {
      ...param,
    },
  )
}

/**
 * 删除
 * @param id
 * @returns
 */
export async function deleteCoordinationApplication(
  id: number,
): Promise<AxiosResponse<Result>> {
  return await $axios.delete(
    `/supervision-api/coordinationApply/deleteApplyData/${id}`,
  )
}

/**
 * 列表提交
 * @param
 * @returns
 */
export async function submitCoordinationApplicationById(
  param: ICoordinationApplicationDetail,
): Promise<AxiosResponse<Result>> {
  return await $axios.post(
    '/supervision-api/coordinationApply/submitApplyInfoById',
    {
      ...param,
    },
  )
}
